<?php
/**
 * Created by PhpStorm.
 * User: 大帅
 * Date: 15-4-26
 * Time: 上午10:36
 *
 *
 */
require_once('/var/www/html/new/d/common/func.inc.php');
include_once '/var/www/html/new/d/module/pwk/class/version.class.php';
include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';
\PFT\Db::Conf($dbConf['remote_1']);
$ver= new Version();
foreach ($_POST as $k=>$v){
    $v=safetxt($v);
    $arr[$k]=$v;
}
$action=safetxt($_REQUEST['action']);
$time=date('y-m-d h:i:s',$_SERVER['REQUEST_TIME']);
switch($action){
    case "homeread":
        $num=intval($arr[$k]);
        $list_html = '';
        if($num){
            $ver_list=$ver->ver_sel($num);
            $res = make_array($ver_list);
        }else {
            $ver_list = $ver->ver_more();
            $res = make_array($ver_list);
        }
        echo json_encode($res);
    break;
    case "create":
        $ver->ver_add($arr['title'],$arr['content'],$_SESSION['sdtype'],$time);
        break;
    case "edit":
        $ver->ver_upd($arr['id'],$arr['title'],$arr['content'],$_SESSION['sdtype'],$time);
        break;
    case "read":
        $id=$arr['id'];
        $ver_content=$ver->ver_sel(1,$id);
        $res=json_encode($ver_content[0]);
        echo $res;
        break;
    case "delete":
        $id=safetxt($_POST['id']);
        $ver->ver_del($id,$_SESSION['sdtype']);
        break;
    default:
        break;
}
function make_array($array){
    if(count($array)){
        foreach($array as $k => $v){
            $array[$k]['access_date'] = substr($v['access_date'],5,5);//截时间 只要月日
        }
        $res = array(
            'status' => 'suc',
            'list'   => $array
        );
    }else{
        $res = array(
            'status' => 'fail'
        );
    }
    return $res;
}
?>